package com.java.userservice.controller;

import com.java.common.model.Result;
import com.java.userservice.model.Role;
import com.java.userservice.model.dto.RolePermissionDTO;
import com.java.userservice.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/list")
    public Result list(@RequestBody Role role) {
        return roleService.list(role);
    }
    @PostMapping("/listAll")
    public List<Role> listAll() {
        return roleService.listAll();
    }

    @PostMapping("/save")
    public Result save(@RequestBody Role role) {
        return roleService.save(role);
    }

    @PostMapping("/modify")
    public Result modify(@RequestBody Role role) {
        return roleService.modify(role);
    }

    @GetMapping("/remove")
    public Result remove(int[] ids) {
        return roleService.remove(ids);
    }

    /**
     * 查询权限列表
     * @return
     */
    @GetMapping("/listPermission")
    public Result listPermission() {
        return roleService.listPermission();
    }

    /**
     * 查询角色已有权限
     * @param id
     * @return
     */
    @GetMapping("/listPermissionByRoleId/{id}")
    public Result listPermissionByRoleId(@PathVariable Integer id) {
        return roleService.listPermissionByRoleId(id);
    }

    /**
     * 添加权限
     * @param rolePermissionDTO
     * @return
     */
    @PostMapping("/savePermission")
    public Result savePermission(@RequestBody RolePermissionDTO rolePermissionDTO) {
        return roleService.savePermission(rolePermissionDTO);
    }
}
